﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TheFinalCountDown.UI
{
	public partial class SettingsForm : Form
	{
		private DateTime oldDate;

		public SettingsForm()
		{
			InitializeComponent();
		}

		public void SetTargetDate(DateTime targetDate)
		{
			datePicker.Value = targetDate;
			hoursPicker.Value = targetDate.Hour;
			minutesPicker.Value = targetDate.Minute;
			secondsPicker.Value = targetDate.Second;
		}

		public DateTime GetTargetDate()
		{
			DateTime date = datePicker.Value;
			DateTime targetDate = new DateTime(
				date.Year,
				date.Month,
				date.Day,
				(int)hoursPicker.Value,
				(int)minutesPicker.Value,
				(int)secondsPicker.Value);

			return targetDate;
		}

		#region Forms

		private void OnFormLoad(object sender, EventArgs e)
		{
			SetTargetDate(Program.MainForm.CountDown.TargetDate);
			UserSettings.Instance.IsEffectiveTime = effectiveCheckbox.Checked;
			oldDate = UserSettings.Instance.TargetDate;
			effectiveCheckbox.Checked = UserSettings.Instance.IsEffectiveTime;

			setButton.Enabled = false;
		}

		private void OnValueChanged(object sender, EventArgs e)
		{
			setButton.Enabled = true;
			cancelButton.Enabled = true;
		}

		private void OnEffectiveCheckChanged(object sender, EventArgs e)
		{
			UserSettings.Instance.IsEffectiveTime = effectiveCheckbox.Checked;
		}

		#endregion

		#region Buttons

		private void OnCancelButton(object sender, EventArgs e)
		{
			SetTargetDate(oldDate);
			cancelButton.Enabled = false;
		}

		private void OnSetButton(object sender, EventArgs e)
		{
			Program.MainForm.CountDown.TargetDate = GetTargetDate();

			cancelButton.Enabled = true;
			setButton.Enabled = false;
		}

		#endregion
	}
}
